package base_grammar

import (
	"fmt"
)

/*
类型与接口之间的关系

一个类型可以实现多个接口
多个类型可以实现同一个接口（多态）

*/

type USB interface {
	read()
	write()
}

type Computer struct {
}

func (computer Computer) read() {
	fmt.Println("computer read")
}

func (computer Computer) write() {
	fmt.Println("computer write")
}

type Mobile struct {
}

func (mobile Mobile) read() {
	fmt.Println("mobile read")
}

func (mobile Mobile) write() {
	fmt.Println("mobile write")
}

func Interface_test1() {
	computer := Computer{}
	mobile := Mobile{}

	computer.read()
	computer.write()
	mobile.read()
	mobile.write()

	/*
		var oc OpenClose
		此处会编译出错  提示Door没有实现close方法
		oc = Door{}
	*/
}

type OpenClose interface {
	open()
	close()
}

type Door struct{}

func (door Door) open() {
	fmt.Println("open")
}
